<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="root">
    <button @click="step('Child1')">第1步</button>
    <button @click="step('Child2')">第2步</button>
    <button @click="step('Child3')">第3步</button>
    <!-- 动态组件 -->
    <!-- 状态保持 -->
    <keep-alive>
      <component :is="name"></component>
    </keep-alive>
  </div>
  <script src="./js/vue.js"></script>
  <script>
    // 子组件
    const Child1 = {
      template: `<div>
        <input type="text"/>
      </div> `
    }
    const Child2 = {
      template: ` <div> 第2步</div> `
    }
    const Child3 = {
      template: ` <div> 第3步</div> `
    }
    // 父组件
    new Vue({
      el: '#root',
      data: {
        name: 'Child1'
      },
      // 局部组件
      components: { Child1, Child2, Child3 },
      methods: {
        step(name) {
          this.name = name
        }
      },
    })
  </script>
</body>

</html>